//
//  PBMineButton.m
//  ProjectBoss
//
//  Created by 聂志康 on 2018/6/22.
//  Copyright © 2018年 weipainetwork. All rights reserved.
//

#import "PBMineButton.h"

@interface PBMineButton ()
@property (nonatomic, strong) UILabel *tagLabel;
@end

@implementation PBMineButton

-(void)layoutSubviews {
    [super layoutSubviews];
    // Center image
//    CGPoint center = self.imageView.center;
//    center.x = self.frame.size.width/2;
//    center.y = self.frame.size.height/2-kHeight(10);
//    self.imageView.center = center;
//
//    //Center text
//    CGRect newFrame = [self titleLabel].frame;
//    newFrame.origin.x = 0;
//    newFrame.origin.y = self.imageView.frame.size.height + kHeight(24);
//    newFrame.size.width = self.frame.size.width;
//
//    self.titleLabel.frame = newFrame;
//    self.titleLabel.textAlignment = NSTextAlignmentCenter;
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.tagLabel];
    }
    return self;
}

- (void)setTaggerNumber:(int)taggerNumber {
    _taggerNumber = taggerNumber;
    if (taggerNumber > 0) {
        self.tagLabel.hidden = false;
    } else {
        self.tagLabel.hidden = true;
    }
    NSString *alertNumberLabelText = [NSString stringWithFormat:@"%d",taggerNumber];
    self.tagLabel.text = alertNumberLabelText;
    if (taggerNumber >= 10 && taggerNumber <= 99) {
        self.tagLabel.frame = CGRectMake((ScreenWidth-24)/5/2-kHeight(10), 5, 25, 20);
    } else if (taggerNumber > 99) {
        self.tagLabel.text = @"99+";
        self.tagLabel.frame = CGRectMake((ScreenWidth-24)/5/2-kHeight(10), 5, 34, 20);
    } else {
        self.tagLabel.frame = CGRectMake((ScreenWidth-24)/5/2-kHeight(8), 5, 20, 20);
    }
}

- (UILabel *)tagLabel {
    if (!_tagLabel) {
        _tagLabel = [[UILabel alloc] initWithFrame:CGRectMake((ScreenWidth-24)/5/2+kHeight(2), 5, 20, 20)];
        _tagLabel.backgroundColor = UIColor.whiteColor;
        _tagLabel.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:14];
        _tagLabel.layer.shadowColor = UIColor.blackColor.CGColor;
        _tagLabel.layer.shadowOffset = CGSizeZero;
        _tagLabel.layer.shadowRadius = 1.5;
        _tagLabel.layer.cornerRadius = 10;
        _tagLabel.layer.masksToBounds = true;
        _tagLabel.backgroundColor = RGBColor(232, 78, 64);
        _tagLabel.textColor = [UIColor whiteColor];
        _tagLabel.textAlignment = NSTextAlignmentCenter;
        _tagLabel.hidden = true;
    }
    return _tagLabel;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
